﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		pageAdvice = getProperty("serviceFactory").getBean("pageAdvice");

		teacherId = sessionAdvice.getAutherUserID();
		
		hashCode = event.getArg("Sign");
		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");

		checked = false;
		
		try{
			
			if ( decrypt(hashCode, teacherId, "PBEWithMD5AndDES", "Hex") eq taskId ) {
				
				/* 载入补考教学任务 */
				
				sql = "SELECT 
							a.mark_need, a.mark_done,
							t_course.mark_mode, a.task_prog 
						FROM 
							t_resitplan a 
							INNER JOIN t_course ON t_course.cid = a.cid 
						WHERE 
							a.task_id = :taskId ";
							
				queryObj = new query( datasource=application.dnsSlave );
				
				queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
				
				rs_task = queryObj.execute( sql=sql ).getResult();

				progress = 0;
				
				if ( rs_task.mark_need ) {
					progress = int( rs_task.mark_done * 10000 / rs_task.mark_need ) / 100;
				}
				
				/* 生成分页 */
				pageAdvice.setTotleRow( rs_task.mark_need );
				pageAdvice.setStartRow( event.getArg("Start", 1) );
				pageAdvice.setPage( event.getArg("Page", 1) );
				
				pageAdvice.setRowPerPage( 30 );
				
				pageArray = pageAdvice.getPageList();

				if ( rs_task.mark_mode eq "0" and ( rs_task.task_prog eq "0" or rs_task.task_prog eq "1" or rs_task.task_prog eq "2" or rs_task.task_prog eq "4" ) ) {
					
					checked = true;
					
					/* 更新成绩提交状态 */
					transaction {
						
						sql = "UPDATE 
									t_resitplan 
								SET 
									task_prog = '1' 
								WHERE 
									task_id = :taskId ";
									
						queryObj = new query( datasource=application.dnsMaster );
						
						queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
						
						queryObj.execute( sql=sql );
					}
					
					/* 传递参数处理 */
					pageArgs = structNew();
					structInsert( pageArgs, "TSK", taskId, true );
					structInsert( pageArgs, "TT", taskType, true );
					structInsert( pageArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true );
					
					targetArgs = structNew();
					structInsert( targetArgs, "TSK", taskId, true );
					structInsert( targetArgs, "TT", taskType, true );
					structInsert( targetArgs, "Sign", encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex"), true );

					/* 载入成绩提交名单 */
					sql = "SELECT 
								a.scc_id, 
								t_student.stu_id, t_student.stu_name,
								t_class.cls_name, t_subject.sbj_short,
								a.mark_resit, a.mark_renote 
							FROM
								t_temp_mark_resit a
								INNER JOIN t_student ON t_student.stu_id = a.stu_id
								INNER JOIN t_class ON t_class.cls_id = t_student.cls_id
								INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id
							WHERE
								a.task_id = :taskId 
							ORDER BY 
								a.stu_id ";
								
					queryObj = new query( datasource=application.dnsSlave );
					
					queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
					
					rs_student = queryObj.execute( sql=sql ).getResult();

					startRow = pageAdvice.getStartRow();
					endRow = startRow + pageAdvice.getRowPerPage() - 1;
				}

			}
			
		}
		catch (any ecpt) {
		}
		
		/* 判断当前显示课表内容 */
		currentTab = event.getArg("TabID", "labSheet");
		
	</cfscript>
</cfsilent>
<!---<div id="out"></div>--->
<cfif checked >

		<div class="UItab">
			<div class="tabLables">
				<span <cfif currentTab eq "labSheet">class="active"</cfif> id="labSheet" tabTarget="Sheet">网上成绩提交</span>
				<!---<span <cfif currentTab eq "labExcel">class="active"</cfif> id="labExcel" tabTarget="Excel">导入电子表格成绩</span>--->
			</div>
		</div>
		<script language="javascript" type="text/javascript">
			//<![CDATA[
			<!--
			$(document).ready(function() {
						
				/* init Tab */
				$("div.tabContent").hide();
				$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
				$("div.tabLables > span").click(function(){
					var $targetID = $(this).attr("tabTarget");
						
					$("div.tabLables span").removeClass("active");
					$(this).addClass("active");
							
					$("div.tabContent").not('[id="' + $targetID + '"]').hide();
					$("div.tabContent#" + $targetID).show();
				});
						
			});
			// -->
			//]]>
		</script>

		<div id="Sheet" class="tabContent">
			
			<div class="noticeBlock">
				<h3>课程补考成绩</h3>
				<p>
					<span class="img icon16x16 message"></span>
					请注意, 这里需要提交的是课程补考成绩. 当前课程成绩按照百分制提交, 课程考核分数应当填写为 <em>0-100</em> 之间的数字. 在登录成绩期间, 您可以使用键盘的 <b>Tab</b> 按键快速在单元格之间切换.
				</p>
				<hr/>
			</div>
			
			<div class="UIProgressbar">
				<span class="progressBar" id="pb1">0%</span>
				<!---<p id="output">成绩提交进度</p>--->
			</div>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				$(document).ready(function() {
					/* init Progress */
					$("#pb1").progressBar(
											<cfoutput>#progress#</cfoutput>,
											{
												boxImage : '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
												barImage : {
													0:  '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
													30: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
													70: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
													}
												});
				});
				// -->
				//]]>
			</script>
			
			<!--- 如果计分完成, 则显示跳转到成绩检查页面 --->
			<form id="formRemove" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('taskMarkResitWizardChecker0')#</cfoutput>">
				<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
				<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
				<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
				<div class="lable"><input class="button2" type="submit" value="检查已录入成绩" /></div>
			</form>
			
			<table class="UIEditable">
				<thead>
					<tr>
						<td width="30"></td>
						<td>学号</td>
						<td>姓名</td>
						<td>班级</td>
						<td>专业</td>
						<td width="100">成绩</td>
						<td width="140">备注</td>
						<td width="25"></td>
					</tr>
				</thead>
				<tbody>
					<cfset row = pageAdvice.getOffset() />
                    <cfloop startrow="#startRow#" endrow="#endRow#" query="rs_student">
						<cfset row++ />
						<cfset codeSign = encrypt(rs_student.scc_id, teacherId, "PBEWithMD5AndDES", "Hex") />
						<tr class="editRows studyType<cfoutput>#rs_student.mark_resit#</cfoutput> <cfif event.getArg('Target') eq rs_student.scc_id>lastEdited</cfif>">
							<td class="index"><cfoutput>#row#</cfoutput></td>
							<td><span class="numeric"><cfoutput>#rs_student.stu_id#</cfoutput></span></td>
							<td><cfoutput>#rs_student.stu_name#</cfoutput></td>
							<td><cfoutput>#rs_student.cls_name#</cfoutput></td>
							<td><cfoutput>#rs_student.sbj_short#</cfoutput></td>
							<td>
								<cfif rs_student.mark_renote eq "1">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" <cfif rs_student.mark_resit gte 0>value="<cfoutput>#numberFormat(rs_student.mark_resit, '_._')#</cfoutput>"</cfif> />
									<cfelseif rs_student.mark_renote eq "2">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" value="0" />
									<cfelseif rs_student.mark_renote eq "3">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" value="-" />
									<cfelseif rs_student.mark_renote eq "9">
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" value="0" />
									<cfelse>
									<input onBlur="sendScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '<cfoutput>#codeSign#</cfoutput>');" tabindex="<cfoutput>#row#</cfoutput>" disabled="disabled" class="Mark" type="text" name="Mark<cfoutput>#rs_student.scc_id#</cfoutput>" />
								</cfif>
							</td>
							<td>
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '1', '<cfoutput>#codeSign#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="1" <cfif rs_student.mark_renote eq "1">checked="checked"</cfif>/>无 &nbsp;&nbsp;
								<input onClick="changeScroll('<cfoutput>#rs_student.scc_id#</cfoutput>', '2', '<cfoutput>#codeSign#</cfoutput>');" type="radio" name="MarkNote<cfoutput>#rs_student.scc_id#</cfoutput>" value="2" <cfif rs_student.mark_renote eq "2">checked="checked"</cfif>/>缺考 &nbsp;&nbsp;
							</td>
							<td><span name="MarkStat<cfoutput>#rs_student.scc_id#</cfoutput>" class="stat <cfif rs_student.mark_resit gte 0 or rs_student.mark_renote neq "1">checked<cfelse>todo</cfif>"></span></td>
						</tr>
					</cfloop>
				</tbody>
			</table>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				
				function refreshTask() {
					
					$.post(
							"<cfoutput>#buildURL('apiTaskMarkResitFlush')#</cfoutput>", 
							{
								"TSK": '<cfoutput>#taskId#</cfoutput>',
								"Sign": '<cfoutput>#encrypt(taskId, teacherId, "PBEWithMD5AndDES", "Hex")#</cfoutput>', 
								"seed": (new Date()).getTime()
							},
							function(data) {
								
								var result = $.parseJSON(data);
											
								if ( result.success ) {
									
									$("#pb1").progressBar(
															result.Progress, 
															{
																boxImage : '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbar.gif',
																barImage : {
																	0:  '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_red.gif',
																	30: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_orange.gif',
																	70: '<cfoutput>#getProperty("cdnServer")#</cfoutput><cfoutput>#getContextRoot()#</cfoutput>/acadmicRes/assets/widget/progressbar/images/progressbg_green.gif'
																	}
															});
								
									if ( result.Progress == 100 ) {
										$("#complateNotice").removeClass("hidden_elem");
									}
									
								}
								
							});
					
				}
				
				function sendScroll( chooserId, sign ) {
					
					var $mark =$("input[name='Mark" + chooserId + "']");
					var $markNote = $("input:checked[name='MarkNote" + chooserId + "']");
					var $stat = $("span[name='MarkStat" + chooserId + "']");
					
					var mark = $mark.val();
					var note = $markNote.val();
					
					switch(note) {
						
						case "1":
							
							/* 检查分数 */
							if (mark !="" && mark >=0 && mark <=100) {
								
								$stat.removeClass("delete").removeClass("todo").removeClass("checked").addClass("waiting");
								
								$.post(
										"<cfoutput>#buildURL('apiStudentMarkResitSave')#</cfoutput>", 
										{
											"ChooseID": chooserId, 
											"MarkMode": "0", 
											"Mark": mark, 
											"MarkNote": note, 
											"Sign": sign, 
											"seed": (new Date()).getTime()
										},
										function(data) {
											
											var result = $.parseJSON(data);
											
											if ( result.success ) {
												
												$mark.val( result.Mark );
												
												$stat.removeClass("waiting").addClass("checked");
												
												/* 刷新进度 */
												refreshTask();
											}
											else {
												//alert( result.reason );
												$stat.removeClass("waiting").addClass("delete");
											}
										
										});
								
							}
							else {
								$stat.removeClass("todo").removeClass("checked").removeClass("waiting").addClass("delete");
							}
							
							break;
						
						case "2":
						case "9":
							
							$stat.removeClass("delete").removeClass("todo").removeClass("checked").addClass("waiting");
							
							$.post(
									"<cfoutput>#buildURL('apiStudentMarkResitSave')#</cfoutput>", 
									{
										"ChooseID": chooserId, 
										"MarkMode": "0", 
										"Mark": "-1", 
										"MarkNote": note, 
										"Sign": sign, 
										"seed": (new Date()).getTime()
									},
									function(data) {
										
										//$("#out").html(data);
										var result = $.parseJSON(data);
											
										if ( result.success ) {
											
											$stat.removeClass("waiting").addClass("checked");
											
											/* 刷新进度 */
											refreshTask();
										}
										else {
											//alert( result.reason );
											$stat.removeClass("waiting").addClass("delete");
										}
										
									});
							
							break;
						
					}


				}
				
				function changeScroll( chooserId, markNote, sign ) {

					var $input = $("input[name='Mark" + chooserId + "']");
					
					switch(markNote) {
						case "1":
							$input.val("").removeAttr("disabled");
							break;
						case "2":
							$input.val("0").attr("disabled", "disabled");
							sendScroll(chooserId, sign);
							break;
						case "3":
							$input.val("-").attr("disabled", "disabled");
							sendScroll(chooserId, sign);
							break;
						case "9":
							$input.val("0").attr("disabled", "disabled");
							sendScroll(chooserId, sign);
							break;
						}
					}

				
				// -->
				//]]>
			</script>

			<div class="pagination">
				<div class="summary">Page:<cfoutput>#pageAdvice.getPage()#</cfoutput>/<cfoutput>#pageAdvice.getPageCount()#</cfoutput> Totle:<cfoutput>#pageAdvice.getTotleRow()#</cfoutput></div>
				<div class="lists">
					<cfloop from="1" to="#arrayLen(pageArray)#" index="page">

						<cfset structInsert( pageArgs, "Start", pageArray[page][2], true ) />
						<cfset structInsert( pageArgs, "Page", pageArray[page][3], true ) />

						<cfswitch expression="#pageArray[page][1]#">
							<cfcase value="D">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>"><cfoutput>#pageArray[page][3]#</cfoutput></a>
							</cfcase>
							<cfcase value="C">
								<span><cfoutput>#pageArray[page][3]#</cfoutput></span>
							</cfcase>
							<cfcase value="F">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">First</a>
							</cfcase>
							<cfcase value="P">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Previous</a>
							</cfcase>
							<cfcase value="N">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Next</a>
							</cfcase>
							<cfcase value="L">
								<a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Last</a>
							</cfcase>
						</cfswitch>
					</cfloop>
				</div>
			</div>
			
		</div>
		
		<div id="Excel" class="tabContent">
			
			<div class="noticeBlock">
				<h3>上传考核成绩</h3>
				<p>
					<span class="img icon16x16 message"></span>
					请严格按照如下的数据模板在电子表格文件中录入成绩数据. 点击<a href="<cfoutput>#buildURL('importTaskMarkResitTemplate', targetArgs)#</cfoutput>">下载学生成绩录入模板</a>, 在录入信息时请勿更改第一行表头内容.
				</p>
				<hr/>
				<table>
					<tr>								
						<td>学号</td><td>姓名</td><td>考核成绩</td>
					</tr>
					<tr>
						<td>成绩对应学号</td><td>学生姓名</td><td>百分制成绩(数字) / 缺考 / 违纪</td>
					</tr>
				</table>
			</div>
			
			<form target="output" onSubmit="javascript:return processVerfiyForm('formImport');" id="formImport" class="formWrapper" method="post" enctype="multipart/form-data" action="<cfoutput>#buildURL('importTaskMarkResitDo')#</cfoutput>">
				
				<input type="hidden" name="TSK" value="<cfoutput>#taskId#</cfoutput>" />
				<input type="hidden" name="TT" value="<cfoutput>#taskType#</cfoutput>" />
				<input type="hidden" name="Sign" value="<cfoutput>#encrypt(taskId, teacherId, 'PBEWithMD5AndDES', 'Hex')#</cfoutput>" />
				
				<div class="label">
					<span class="req">*</span><b>导入数据文件</b>
					<input name="upload" id="upload" type="file" verification="required" />
				</div>
						
				<div class="lable"><input id="importTrigger" class="button" type="submit" value="导入成绩数据" /></div>
			</form>
			
			<script language="javascript" type="text/javascript">
				//<![CDATA[
				<!--
				$(document).ready(function() {
					$("#importTrigger").click(function(){
						$("#output").attr("src","about:blank").removeClass("hidden_elem");
					});
				});
				// -->
				//]]>
			</script>

			<iframe name="output" id="output" class="UIframeBox hidden_elem" src="about:blank" frameborder="0"></iframe>
			
		</div>
	
	<cfelse>
	
		<div class="systemNotice">
			<h3><span class="img icon16x16 message"></span>错误的参数</h3>
			<p>请关闭浏览器重新登录 或 检查您是否使用了正确访问方式</p>
		</div>
</cfif>